package com.magold.background;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.IDrawHandler;
import org.andengine.entity.shape.IAreaShape;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.util.GLState;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import com.magold.context.IContext;
import com.magold.logic.LogicConstants;
import com.magold.sprite.MultiTextureSprite;

public class Cell implements IDrawHandler {

	public static class Constants extends LogicConstants {
		public ITiledTextureRegion mLightingTexture;

		public Constants(IContext pActivity) {
			super(pActivity);
		}
	}
	
	public static void customize(Constants pConstants) {
		VertexBufferObjectManager vbom = pConstants.mContext.getVertexBufferObjectManager();
		sSprite = new MultiTextureSprite(0, 0, 1, pConstants.mLightingTexture, vbom);
		sWidth = sSprite.getWidth();
		sHeight = sSprite.getHeight();
	}
	
	private static IAreaShape sSprite;
	private static float sWidth;
	private static float sHeight;

	private boolean mVisible;
	private int mXIndex;
	private int mYIndex;

	public Cell(int pXIndex, int pYIndex, boolean pVisible) {
		mVisible = pVisible;
		mXIndex = pXIndex;
		mYIndex = pYIndex;
	}

	public void setPosition(int pXIndex, int pYIndex) {
		mXIndex = pXIndex;
		mYIndex = pYIndex;
	}

	public int getXIndex() {
		return mXIndex;
	}

	public int getYIndex() {
		return mYIndex;
	}


	public void setVisible(boolean pVisible) {
		mVisible = pVisible;
	}

	@Override
	public void onDraw(GLState pGLState, Camera pCamera) {
		sSprite.setPosition(mXIndex*sWidth, mYIndex*sHeight);
		sSprite.setVisible(mVisible);
		sSprite.onDraw(pGLState, pCamera);
	}

	public boolean isVisible() {
		return mVisible;
	}

}
